package com.cspg.ssss.service;

import com.cspg.ssss.domain.AddScoreDept;
import com.cspg.ssss.domain.GradeRoleUser;
import com.cspg.ssss.domain.RoleDepartEntity;
import com.cspg.ssss.repository.GradeRoleUserMapper;
import com.cspg.ssss.repository.SuperAdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GradeRoleUserService {

    @Autowired
    GradeRoleUserMapper mapper;

    @Autowired
    SuperAdminMapper superAdminMapper;

    public List<GradeRoleUser> getRoleListByUserid(String user_id){

        HashMap<String,Object> condition = new HashMap<String, Object>();
        condition.put("user_id",user_id);
        return mapper.findDepartRoleListByUserid(condition);
    }

    public List<String> getGradeDepartsByUserid(String user_id){
        HashMap<String,Object> condition = new HashMap<String, Object>();
        condition.put("user_id",user_id);
        condition.put("option_type",2);
        List<GradeRoleUser> retList = mapper.findDepartRoleListByUserid(condition);

        if(retList != null && retList.size() > 0){
            List<String> retDeparts = new ArrayList<String>();
            for(int i=0;i<retList.size();i++){
                //处理字符串（去掉部门全路径里面的"超高压输电公司/"共8个字符）
                retDeparts.add(retList.get(i).getDepart_pathname());
            }
            return retDeparts;
        }

        return null;
    }

    public List<String> getApproveDepartsByUserid(String user_id,int optype){
        HashMap<String,Object> condition = new HashMap<String, Object>();
        condition.put("user_id",user_id);
        condition.put("option_type",optype);
        List<GradeRoleUser> retList = mapper.findDepartRoleListByUserid(condition);

        if(retList != null && retList.size() > 0){
            List<String> retDeparts = new ArrayList<String>();
            for(int i=0;i<retList.size();i++){
                //处理字符串（去掉部门全路径里面的"超高压输电公司/"共8个字符）
                retDeparts.add(retList.get(i).getDepart_pathname());
            }
            return retDeparts;
        }

        return null;
    }

    public List<String> getUserListByDepartRoles(String depart_path,int optType){
        HashMap<String,Object> condition = new HashMap<String, Object>();
        condition.put("depart_pathname",depart_path);
        condition.put("option_type",optType);
        List<GradeRoleUser> retList = mapper.findUserListByDepartRole(condition);
        List<String> retUsrls = new ArrayList<String>();
        if(retList != null && retList.size() > 0){
            for(int i=0;i<retList.size();i++){
                retUsrls.add(retList.get(i).getUser_id());
            }
        }

        return retUsrls;

    }

    public List<RoleDepartEntity> getRoleDepartsByOptionType(int optType){
        return mapper.findRoleListByOptType(optType);
    }

    public List<AddScoreDept> getAddScoreDepts(Map<String,Object> condition){
        return superAdminMapper.selectScroeAddDept(condition);
    }

    /**
     * 获取公司级别职能部门
     * @return
     */
    public List<AddScoreDept> getCompanyDeparts(){
        Map<String,Object> condition = new HashMap<String, Object>();
        condition.put("depart_type",0);
        return superAdminMapper.selectScroeAddDept(condition);
    }

    /**
     * 获取所有单位的职能部门
     * @return
     */
    public List<AddScoreDept> getGroupDeparts(){
        Map<String,Object> condition = new HashMap<String, Object>();
        condition.put("depart_type",1);
        return superAdminMapper.selectScroeAddDept(condition);
    }

}
